<?php
/**
 * Feedback Comment Model
 *
 * @author hiscaler <hiscaler@gmail.com>
 * @link http://www.yuandot.com/
 * @copyright Copyright &copy; 2009-2010 Yuandot Information Technology CO.,LTD.
 * @license http://doit.yuandot.com/license/
 */

class FeedbackComment extends CActiveRecord {
    /**
     * The followings are the available columns in table 'www_feedback_comments':
     * @var integer $id
     * @var integer $feedback_id
     * @var string $body
     * @var string $body_formatted
     * @var integer $created
     * @var integer $updated
     */
     
    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{feedback_comments}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
        return array(
            array('feedback_id, body', 'required'),
            array('feedback_id, created, updated', 'numerical', 'integerOnly' => true),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
        return array(
            array(self::BELONGS_TO, 'Feedback', 'feedback_id', 'joinType'=>'INNER JOIN'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'Id',
            'feedback_id' => 'Feedback',
            'body' => Yii::t('feedbackComment', 'body'),
            'body_formatted' => Yii::t('feedbackComment', 'body'),
            'created' => Yii::t('common', 'created'),
            'updated' => Yii::t('comment', 'updated'),
        );
    }

    protected function beforeValidate() {
        $parser = new CMarkdownParser;
        $this->body_formatted = $parser->safeTransform($this->body);
        return true;
    }

    public function behaviors() {
        return array(
            'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
                'createAttribute' => 'created',
                'updateAttribute' => 'updated',
            )
        );
    }
}